package com.java.zhuiyun.api.teacher.mapper;


import com.java.zhuiyun.api.sys_dict.entity.SysDict;
import com.java.zhuiyun.api.teacher.entity.Teacher;
import com.java.zhuiyun.api.teacher.model.TeacherModel;
import com.java.zhuiyun.common.mapper.BaseMapper;
import io.swagger.models.auth.In;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @InterfaceName BackCourseMapper
 * @Description TODO
 * @Author 杨友朋
 * @Date 2023/8/14 15:17
 **/
@Mapper
public interface TeacherMapper extends BaseMapper<Teacher> {
    /**
    * @Author 杨友朋
    * @Description TODO 查询数量
    * @Date 2023/8/15 10:19
    * @Return
    * @param
    */
    @Select("select count(id) from teacher where del_flag=0")
    Integer selectCountTeacher();

    /**
    * @Author 杨友朋
    * @Description TODO 全查教师信息
    * @Date 2023/8/15 11:06
    * @Return
    * @param
    */
    @Select("<script>select t.id,t.teacher_name,t.teacher_img,t.education_id,t.user_id,t.education_img," +
            "t.seniority,t.teacher_info,t.live_number,u.gender,u.email,u.phone,u.is_disable,u.address,u.password " +
            "from teacher t,sys_user u " +
            "where t.user_id = u.id and t.del_flag = 0 and u.del_flag = 0 and u.is_disable = 0 " +
            "<if test='teacherName != null and teacherName != &quot;&quot;'> and t.teacher_name like concat('%', #{teacherName}, '%')</if> " +
            "<if test='educationId != null and educationId != &quot;&quot;'> and t.education_id = #{educationId}</if> " +
            "<if test='phone != null and phone != &quot;&quot;'> and u.phone like concat('%', #{phone}, '%')</if>"+
            "</script>")

    List<TeacherModel> selectTeacher(TeacherModel teacherModel);

    /**
    * @Author 杨友朋
    * @Description TODO 单查教师信息
    * @Date 2023/8/15 11:06
    * @Return
    * @param
    */
    @Select("select t.id,t.teacher_name,t.teacher_img,t.education_id,t.user_id,t.education_img," +
            "t.seniority,t.teacher_info,t.live_number,u.gender,u.email,u.phone,u.is_disable,u.address,u.password " +
            "from teacher t,sys_user u " +
            "where t.user_id=u.id and t.del_flag=0 and u.del_flag=0 and u.is_disable=0 and t.id=#{id}")
    TeacherModel selectTeacherById(Integer id);

    @Select("select * from sys_dict where del_flag=0 and dict_type=#{type}")
    List<SysDict> selectEducationDict(String type);

    @Update("update teacher set del_flag=1 where id=#{id}")
    Integer delTeacher(Integer id);

    /**
    * @Author 杨友朋
    * @Description TODO 修改
    * @Date 2023/8/16 20:35
    * @Return
    * @param
    */
    @Update("<script>" +
            "update teacher set " +
            "<if test='teacherName!=null'>teacher_name=#{teacherName},</if> " +
            "<if test='teacherImg!=null'>teacher_img=#{teacherImg},</if> " +
            "<if test='educationId!=null'>education_id=#{educationId},</if> " +
            "<if test='educationImg!=null'>education_img=#{educationImg},</if> " +
            "<if test='seniority!=null'>seniority=#{seniority},</if> " +
            "<if test='teacherInfo!=null'>teacher_info=#{teacherInfo},</if> " +
            "<if test='updateTime!=null'>update_time=#{updateTime} </if> " +
            "where id=#{id}" +
            "</script>")
    Integer upTeacher(Teacher teacher);

    @Select("select * from teacher where del_flag=0")
    List<Teacher> selectT();
}
